﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Gmis.Web.Common;
using Gmis.Public;

namespace Gmis.Web
{
    public partial class index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack) return;
            //
           // GetVideo(); 
        }

        //获取党支部组织结构
        public string GetPartyOrg()
        {
            BLL.Branch bll = new BLL.Branch();
            List<Model.Branch> list = bll.GetModelList(" 1=1 Order By sNumber ");

            if (list == null || list.Count < 1)
            {
                return "没有数据";
            }

            string returnValue = "";
            foreach (Model.Branch dr in list)
            {              
                returnValue += string.Format("<li>{0}  {1}</li>", dr.sName,dr.sPosition);
            }

            return returnValue;
        }

        //获取村委会组织结构
        public string GetVillageOrg()
        {
            BLL.Committee bll = new BLL.Committee();
            List<Model.Committee> list = bll.GetModelList(" 1=1 Order By sNumber ");

            if (list == null || list.Count < 1)
            {
                return "没有数据";
            }

            string returnValue = "";
            foreach (Model.Committee dr in list)
            {
                returnValue += string.Format("<li>{0}  {1}</li>", dr.sName, dr.sPosition);
            }

            return returnValue;
        }

        //获取村民议事会组织结构
        public string GetVSendoOrg()
        {
            BLL.VSenado bll = new BLL.VSenado();
            List<Model.VSenado> list = bll.GetModelList(" 1=1 Order By sNumber ");

            if (list == null || list.Count < 1)
            {
                return "没有数据";
            }

            string returnValue = "";
            foreach (Model.VSenado dr in list)
            {
                returnValue += string.Format("<li>{0}  {1}</li>", dr.sName, dr.sPosition);
            }

            return returnValue;
        }

        //获取民主议事会组织结构
        public string GetDSendoOrg()
        {
            BLL.DSenado bll = new BLL.DSenado();
            List<Model.DSenado> list = bll.GetModelList(" 1=1 Order By sNumber ");

            if (list == null || list.Count < 1)
            {
                return "没有数据";
            }

            string returnValue = "";
            foreach (Model.DSenado dr in list)
            {
                returnValue += string.Format("<li>{0}  {1}</li>", dr.sName, dr.sPosition);
            }

            return returnValue;
        }

        //获取村务监督小组组织结构
        public string GetVSuperviseOrg()
        {
            BLL.VSupervise bll = new BLL.VSupervise();
            List<Model.VSupervise> list = bll.GetModelList(" 1=1 Order By sNumber ");

            if (list == null || list.Count < 1)
            {
                return "没有数据";
            }

            string returnValue = "";
            foreach (Model.VSupervise dr in list)
            {
                returnValue += string.Format("<li>{0}  {1}</li>", dr.sName, dr.sPosition);
            }

            return returnValue;
        }

        //财务理财监督小组
        public string GetFSuperviseOrg()
        {
            BLL.FSupervise bll = new BLL.FSupervise();
            List<Model.FSupervise> list = bll.GetModelList(" 1=1 Order By sNumber ");

            if (list == null || list.Count < 1)
            {
                return "没有数据";
            }

            string returnValue = "";
            foreach (Model.FSupervise dr in list)
            {
                returnValue += string.Format("<li>{0}  {1}</li>", dr.sName, dr.sPosition);
            }

            return returnValue;
        }
        //村庄概况
        public string GetVillage()
        {
            BLL.Village bll = new BLL.Village();
            DataSet ds = bll.GetList(1, "", "dCreate Desc");
            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return "请录入村庄数据";
            }
           return  ds.Tables[0].Rows[0]["sDescription"].ToString();
           
        }

        //获取视频
        public void GetVideo()
        {
           
            BLL.NewsFile bll = new BLL.NewsFile();
            DataSet ds = bll.GetList(1, " sType = 'video' ", " dDate Desc ");

            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return;
            }
            DataRow dr = ds.Tables[0].Rows[0];            
            string file = ResolveUrl("~/UploadFile/Video/" + dr["sSavePath"].ToString() + "/" + dr["sId"].ToString() + dr["sFormat"].ToString());

            Flv objFlv = new Flv(293, 235, file);
            //this.ltl_Flv.Text = objFlv.Player();

        }

        //获取滚动图片
        public string GetImage()
        {
            BLL.NewsFile bll = new BLL.NewsFile();
            DataSet ds = bll.GetList(7, " sType = 'image' ", " dDate Desc ");

            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return "没有图片数据";
            }
            string str = "<td class=\"sty_1\"><a href=\"UI/NewsDetail.aspx?type=file&sId={0}\" target=\"_blank\">";
            str += "<img src=\"{1}\" width=\"174\" height=\"120\" /></a></td>";
            string resultStr = "";
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string imgFile = "UploadFile/Image/" + dr["sSavePath"].ToString() + "/" + dr["sId"].ToString() + dr["sFormat"].ToString();
                resultStr += string.Format(str,dr["sID"].ToString(), imgFile);
            }
            return resultStr;
        }

        //各专题新闻
        public string GetColumn(string columnName)
        {
            BLL.News bll = new BLL.News();
            DataSet ds = bll.GetList(7, "c.sName='" + columnName + "'", "n.dDate");//news n  column c  village v
            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return "";
            }
            string returnValue = "";
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string sTitle = dr["sTitle"].ToString();
                sTitle = sTitle.Length > 15 ? sTitle.Substring(0, 15) : sTitle;
                returnValue += string.Format("<li><a href=\"UI/NewsDetail.aspx?Type=&sId={0}\" target=\"_blank\">{1}...</a></li>",dr["sId"].ToString(), sTitle);
            }
            return returnValue;
        }
        //各专题新闻
        public string GetColumn(string columnName,int titleNum)
        {
            BLL.News bll = new BLL.News();
            DataSet ds = bll.GetList(7, "c.sName='" + columnName + "'", "n.dDate");//news n  column c  village v
            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                return "";
            }
            string returnValue = "";
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string sTitle = dr["sTitle"].ToString();
                sTitle = sTitle.Length > titleNum ? sTitle.Substring(0, titleNum) : sTitle;
                returnValue += string.Format("<li><a href=\"UI/NewsDetail.aspx?type=&sId={0}\" target=\"_blank\">{1}...</a></li>", dr["sId"].ToString(), sTitle);
            }
            return returnValue;
        }
    
        protected void cmd_Ok_Click(object sender, ImageClickEventArgs e)
        {
            string loginName = txt_UserName.Text.Trim();
            string passWord = txt_Password.Text;
            if (loginName == "" || passWord == "")
            {
                ltl.Text = "用户名或密码不能为空";
                return;
            }
            BLL.LogUser bll = new BLL.LogUser();
            DataSet ds = bll.GetList(" sLoginName = '" + loginName + "' ");
            if (ds == null || ds.Tables[0].Rows.Count < 1)
            {
                ltl.Text = "没有找到该用户";
                return;
            }
            DataRow dr = ds.Tables[0].Rows[0];
            if (dr["sPassWord"].ToString() != passWord)
            {
                ltl.Text = "密码错误";
                return;
            }
            CookieFunction.SetCookie("userId", dr["sId"].ToString());
            CookieFunction.SetCookie("userName", dr["sName"].ToString());
            Response.Redirect("~/Manage/Main.aspx");
        }

        protected void cmd_Reset_Click(object sender, ImageClickEventArgs e)
        {
            txt_Password.Text = "";
            txt_UserName.Text = "";
        }

    }
}